import { Req } from '../../shared/request/request'
import { prefix } from '../../shared/client/axios'

export interface ItemRefType {
  num: number
  name: string
  doctor: string
  status: number
  intervalTime: string
  therapyAddress: string
}

export interface ProcessRefType {
  pId: string;
  startTime: string;
  items: ItemRefType[];
}

export interface Pdetail {
  uId:string
  password:string
  name: string
  gender: string
  cardId: string
  birthday: string
  phone: string
  homeAddress: string
  pId: string
  contactPerson: string
  contactPhone: string
  relation: string
}

export function timestampToDate(timestamp: number) {
  const date = new Date(timestamp / 1)
  return date.toLocaleDateString()
}

export function timestampToDateTime(timestamp: number) {
  const date = new Date(timestamp / 1)
  return date.toLocaleString()
}

export function transStatus(num: number) {
  switch (num) {
  case 0: return 'error'
  case 1: return 'wait'
  case 2: return 'process'
  case 3: return 'finish'
  default: return 'wait'
  }
}

export async function reqReport(req: Req): Promise<any> {
  const data = await req('post', `${prefix}/patient/report`, { noToken: false })
  return data
}

export async function reqGetProcess(req: Req): Promise<any> {
  const data = await req('get', `${prefix}/patient/getProcess`, { noToken: false })
  return data
}

export async function reqGetHistory(req: Req): Promise<any> {
  const data = await req('get', `${prefix}/patient/getHistory`, { noToken: false })
  return data
}

export async function reqGetHistoryByDate(req: Req, startTime: string): Promise<any> {
  const data = await req('post', `${prefix}/patient/getHistoryByDate`, { data: { startTime: startTime } , noToken: false })
  return data
}

export async function reqGetInfo(req: Req) {
  const data = await req('get', `${prefix}/patient/getInfo`, { noToken: false })
  return data
}

export async function reqUpdateInfo(req: Req, patient: Pdetail) {
  const data = await req('post', `${prefix}/patient/modifyInfo`, { noToken: false, data: { ...patient } })
  return data
}